package com.gjt.serverSocket;

import java.io.IOException;
import java.net.ServerSocket;

/**
 * Created with Intel IDEA.
 *
 *  查找本地可用的端口
 * @Auther: gjt
 * @Date: 2024/5/9 20:20
 */
public class LocalPortScanner {
    public static void main(String[] args) {
        for (int i = 0; i <= 65535; i++) {
            try{
                // 如果在此端口创建出来说明此端口没有被占用
                ServerSocket socket = new ServerSocket(i);
            }catch (IOException e){
                System.out.println("There is a server on port " + i +".");
            }
        }
    }
}
